home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C & C++ Multimedia Cyber Classroom
/
C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso
/
src
/
fig02_07.jar
/
Ch02
/
Fig02_07
/
Fig02_07.cpp
Wrap
C/C++ Source or Header
|
1997-10-11
|
976b
|
31 lines
// Fig. 2.7: fig02_07.cpp
// Class average program with counter-controlled repetition
#include <iostream.h>
int main()
{
int total, // sum of grades
gradeCounter, // number of grades entered
grade, // one grade
average; // average of grades
// initialization phase
total = 0; // clear total
gradeCounter = 1; // prepare to loop
// processing phase
while ( gradeCounter <= 10 ) { // loop 10 times
cout << "Enter grade: "; // prompt for input
cin >> grade; // input grade
total = total + grade; // add grade to total
gradeCounter = gradeCounter + 1; // increment counter
}
// termination phase
average = total / 10; // integer division
cout << "Class average is " << average << endl;
return 0; // indicate program ended successfully
}